package uicgas.globaldata;

import java.io.Serializable;

public class Pump extends MessagePayload implements Serializable
{
	//public static final String DEACTIVATED = "deactivated";
	//public static final String ACTIVATED = "activated";
	//public static final String DECOMMISSIONED = "decommissioned";

	private int ID; //this is the send/receive id number for all comunications
	//remove socket from this class
	private Transaction current_transaction;
	private double prepaidAmount;
	private States state;
	private int pumpNum = 0; //this is the number of the pump for the physical pump that the motorist sees, ie 1 - 20

	public String toString()
	{
		int tempid = ID +1;
		String temp = "Pump " + tempid;
		return temp;
		
	}
	public Pump()
	{
		ID = -1;
		current_transaction = new Transaction();
		prepaidAmount = 0.00;
		state = States.DEACTIVATED;
	}
	

	public Pump(int newID, Transaction transaction, double newPrepaid,
			States newState)
	{
		ID = newID;
		current_transaction = transaction;
		prepaidAmount = newPrepaid;
		state = newState;
	}

	public int getID()
	{
		return ID;
	}

	public States getState()
	{
		return state;
	}

	public void setTransaction(Transaction transaction)
	{
		current_transaction = transaction;
	}

	public void setState(States newState)
	{
		state = newState;
	}

	public void setPrepaid(double amount)
	{
		prepaidAmount = amount;
	}

	public Transaction getTransaction()
	{
		return current_transaction;
	}

	public double getPrepaidAmount()
	{
		return prepaidAmount;
	}

	public boolean equals(Object toCompare)
	{
		try
		{
			Pump pump = (Pump) toCompare;
			if (this.ID == pump.getID())
				return true;
			else
				return false;

		}
		catch (ClassCastException e)
		{
			return false;
		}
	}

	public static boolean checkValidState(States toCheck)
	{
		if (toCheck != States.DEACTIVATED)
		{
			if (toCheck != States.ACTIVATED)
			{
				if (toCheck != States.DECOMMISSIONED)
					return false;
			}
		}
		return true;
	}


	public void setPumpNum(int pumpNum)
	{
		if(pumpNum !=0 && pumpNum<=20)
		{
			this.pumpNum = pumpNum;
		}
		else
		{
			//keep the pumpNum as is
		}
	}


	public int getPumpNum()
	{
		return pumpNum;
	}

}
